//
// Created by xili on 2024/9/23 17:06.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int maxProfit(vector<int> &prices) {
        int n = prices.size();
        int maxProfit = 0;
        int minBuy = prices[0];
        for (int i = 1; i < n; i++) {
            maxProfit = max(maxProfit, prices[i] - minBuy);
            minBuy = min(minBuy, prices[i]);
        }
        return maxProfit;
    }
};